package ma.jeetconsulting.pocs.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.maven.model.Dependency;

public class DependencyAssembler {
	
	public static Dependency toMavenDependency(
			final ma.jeetconsulting.pocs.domain.Dependency dependency) {
		return new Dependency() {
			private static final long serialVersionUID = 1L;
			{
				setArtifactId(dependency.getArtifactId());
				setGroupId(dependency.getGroupId());
				setVersion(dependency.getVersion());
			}
		};
	}
	
	public static List<ma.jeetconsulting.pocs.domain.Dependency> toModelDependency(
			List<Dependency> dependencies) {
		List<ma.jeetconsulting.pocs.domain.Dependency> modelDependencies = new ArrayList<>(dependencies.size());
		for (Dependency dependency : dependencies) {
			modelDependencies.add(toModelDependency(dependency));
		}
		return modelDependencies;
	}

	public static ma.jeetconsulting.pocs.domain.Dependency toModelDependency(
			Dependency dependency) {
		ma.jeetconsulting.pocs.domain.Dependency modelDependency = new ma.jeetconsulting.pocs.domain.Dependency();
		modelDependency.setArtifactId(dependency.getArtifactId());
		modelDependency.setGroupId(dependency.getGroupId());
		modelDependency.setVersion(dependency.getVersion());
		return modelDependency;
	}
	
	public static ma.jeetconsulting.pocs.domain.Dependency toModelDependency(org.sonatype.aether.graph.Dependency dependency) {
		ma.jeetconsulting.pocs.domain.Dependency modelDependency = new ma.jeetconsulting.pocs.domain.Dependency();
		modelDependency.setArtifactId(dependency.getArtifact().getArtifactId());
		modelDependency.setGroupId(dependency.getArtifact().getGroupId());
		modelDependency.setVersion(dependency.getArtifact().getVersion());
		return modelDependency;
	}

}
